package com.wolf.util;


import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author sdyang
 * @create 2018-04-22 11:14
 **/
public class IPUtil {

    /**
     * 获取本机IP地址
     * @return
     */
    public static String getLocalIP() {
        String ip = null;
        try {
            InetAddress addr = InetAddress.getLocalHost();

            ip = addr.getHostAddress().toString(); //获取本机ip

        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return ip;
    }

    /**
     * 获取本机Hostname
     * @return
     */
    public static String getHostName() {
        String hostName = null;
        try {
            InetAddress addr = InetAddress.getLocalHost();

            hostName = addr.getHostName().toString(); //获取本机计算机名称

        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return hostName;
    }
}
